package cn.tedu.charging.cost.dao.repository.impl;


import cn.tedu.charging.cost.dao.repository.CostRuleFromRedisRepository;
import cn.tedu.charging.cost.pojo.po.CostResultPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.ValueOperations;
import org.springframework.stereotype.Repository;


import java.util.List;

@Repository
public class CostRuleFromRedisRepositoryImpl implements CostRuleFromRedisRepository {

    @Autowired
    RedisTemplate redisTemplate;
    @Override
    public List<CostResultPO> getCostRuleByStationId(Integer stationId) {
        String key="COST_RULE_KEY_"+stationId;
        ValueOperations<String, List<CostResultPO>> valueOperations=redisTemplate.opsForValue();
        List<CostResultPO> costRules =valueOperations.get(key);
        return costRules;
    }

    @Override
    public void setCostRuleByStationId(Integer stationId, List<CostResultPO> costRules) {
        String key="COST_RULE_KEY_"+stationId;
        ValueOperations<String, List<CostResultPO>> valueOperations=redisTemplate.opsForValue();
        valueOperations.set(key,costRules);

    }
}
